home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9026 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: cs.tu-berlin.de!news
  2. From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Is there a standard for * and & placement style?
  5. Date: 28 Feb 1996 02:50:55 GMT
  6. Organization: Technical University of Berlin, Germany
  7. Message-ID: <4h0fuf$pru@news.cs.tu-berlin.de>
  8. NNTP-Posting-Host: 130.149.17.236
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=iso-8859-1
  11. Content-Transfer-Encoding: 8bit
  12.  
  13. gema001@pn.itnet.it (Antonio Romeo) writes:
  14. > >...
  15. > >-- use intelligent variable names
  16. > >...
  17. > a bit more on this:
  18. > intelligent variables names are meaningfull names.
  19. > So 
  20. >     int i; /* loop counter */
  21. >     ...
  22. >     for (i=0;i<MAX; i++)
  23. >         MakeOnArray(arrayname[i]);
  24. >     ...
  25. > does not is a good name. In a loop, i is the current processed element
  26. > of an array, the next or the previous? 
  27. >  Another good practice is to not make
  28. > assumption on variable values after al loop, expecialli in a FOR
  29. > statement. This is true for every language I know. The variable value
  30. > after a loop depend on compiler (not language) decision.
  31.  
  32. As far as I remember the FOR loop is specified as follows:
  33.  
  34. for( expr1; expr2; expr3 )
  35.     statement
  36.  
  37. is equivalent to
  38.  
  39. expr1;
  40. while( expr2 )
  41. {
  42.     statement
  43.     expr3;
  44. }.
  45.  
  46. This means that you may perfectly rely on the value of EVERY variable as long
  47. as your expr2 depends on it somehow. For instance, in
  48.  
  49. for( i=0; i<10; ++i );
  50.  
  51. i=10 after the loop. It does not depend on the compiler. 
  52.  
  53. Bye
  54.  
  55. Roman
  56.